#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
typedef int BTDataType;
typedef struct BinaryTreeNode
{
	BTDataType data;
	struct BinaryTreeNode* left;
	struct BinaryTreeNode* right;
}BTNode;
BTNode* BuyNode(BTDataType x)
{
	BTNode* newnode = (BTNode*)malloc(sizeof(struct BinaryTreeNode));
	if (newnode == NULL)
	{
		perror("malloc fail");
		return NULL;
	}
	newnode->data = x;
	newnode->left = NULL;
	newnode->right = NULL;
	return newnode;
}
BTNode* GreatBinaryTree()
{
	BTNode* n1 = BuyNode(1);
	BTNode* n2 = BuyNode(2);
	BTNode* n3 = BuyNode(3);
	BTNode* n4 = BuyNode(4);
	BTNode* n5 = BuyNode(5);
	BTNode* n6 = BuyNode(6);

	n1->left = n2;
	n1->right = n4;
	n2->left = n3;
	n4->left = n5;
	n4->right = n6;
	return n1;
}
void PrevOrder(BTNode* root)
{
	if (root == NULL)
	{
		printf(" N ");
		return NULL;
	}
	printf("%d ", root->data);
	PrevOrder(root->left);
	PrevOrder(root->right);
}
void InOrder(BTNode* root)
{
	if (root == NULL)
	{
		printf(" N ");
		return NULL;
	}

	InOrder(root->left);
	printf("%d ", root->data);
	InOrder(root->right);
}
void PostOrder(BTNode* root)
{
	if (root == NULL)
	{
		printf(" N ");
		return NULL;
	}

	PostOrder(root->left);
	
	PostOrder(root->right);
	printf("%d ", root->data);
}
int BTreeSize(BTNode* root)
{
	/*if (root == NULL)
		return 0;
	return BTreeSize(root->left) + BTreeSize(root->right) + 1;*/
	return root == NULL ? 0 : BTreeSize(root->left) + BTreeSize(root->right) + 1;
}
int BTreeLeafSize(BTNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	if (root->left == NULL && root->right==NULL)
		return 1;
	return BTreeLeafSize(root->left) + BTreeLeafSize(root->right);
}
int BTreeHeight(BTNode* root)
{
	if (root == NULL)
		return 0;
	int leftheight = BTreeHeight(root->left);
	int rightheight = BTreeHeight(root->right);
	return leftheight > rightheight ? leftheight + 1 : rightheight + 1;
}
int BTreeLevelkSize(BTNode* root,int k)
{
	assert(k > 0);
	if (root == NULL)
		return 0;
	if (k == 1)
		return 1;
	return BTreeLevelkSize(root->left,k-1) + BTreeLevelkSize(root->right,k-1);
}
int main()
{
	BTNode* root = GreatBinaryTree();
	//PrevOrder(root);

	printf("%d ", BTreeLevelkSize(root,3));
	return 0;
}